#ifndef _PROTOCOL_H_
#define _PROTOCOL_H_
#include "Global.h"

typedef struct          
{
    uint8 Head;
    uint8 DeviceID;
    uint8 Cmd;
    uint8 Para[5];
    uint8 CheckSum;
    uint8 End;
}Typedef_Pack;

typedef union 
{
    Typedef_Pack    Detail;
    uint8           Buf[sizeof(Typedef_Pack)];
}U_Pack;

typedef struct 
{
    uint8 fw_ver1;
    uint8 fw_ver2;
    uint8 hw_ver1;
    uint8 hw_ver2;
    uint8 bd_ver:4;     
    uint8 bd_type:4;        // 1-Hall, 2-Encoder
}Typedef_VerInfo;


//---- 帧头 ----//
#define PROTOCOL_HEAD           0xAA
//---- 模块ID ----//
#define PROTOCOL_DEVICE_ID      0x40
//---- 固件版本号[FW_VER1.FW_VER2] ----//
#define PROTOCOL_FW_VER1        1
#define PROTOCOL_FW_VER2        1
//---- 硬件版本号[HW_VER1.HW_VER2] ----//
#define PROTOCOL_HW_VER1        1
#define PROTOCOL_HW_VER2        1  
//---- 电路板名称-类型 ----//
#define PROTOCOL_BD_TYPE_HALL   1
#define PROTOCOL_BD_TYPE_ENC    2
#define PROTOCOL_BD_TYPE        PROTOCOL_BD_TYPE_HALL
#define PROTOCOL_BD_VER         1

//---- 结束符 ----//
#define PROTOCOL_END            0x55

#define TM_SEND_STATE           (100/10)        //  *10ms


extern U_Pack  RecvMsg;
extern Typedef_VerInfo DeviceInfo;

void initProtocol(void);
void Protocol_Send(uint8 cmd, uint8* para, uint8 size_para);
void Protocol_RecvProc(void);
void Protocol_TimeServer(void);
#endif
